/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.lcfgly.Dao;

import com.lcfgly.Database.ShopOnepage;
import com.lcfgly.DatabaseFactory.DataFactoryInterface;
import com.lcfgly.Interface.GetCacheMark;
import com.lcfgly.Interface.UpdateCacheMark;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

/**
 * Onepage表操作
 * @author lcfgly
 */
@Repository
public class OnepageImpl implements Serializable{
    
    private final String table="shop_onepage";
    private final String sqlheader="SELECT tid,title,body,writer,writeruid,updatetime FROM shop_onepage ";
    
    @Autowired
        @Qualifier("databaseshoprice")
    private DataFactoryInterface dataFactory;
    
    /**
     * 更新当页面
     * @param arg0 
     * @param writeruid 用户ID 
     * @return
     * @throws SQLException 
     */
    @UpdateCacheMark("shopOnepage_${0.tid}")
    public int updateWithWriteruid(ShopOnepage arg0,int writeruid) throws SQLException {
        return dataFactory.update(table,arg0, "tid=? AND writeruid = ?", arg0.getTid(),writeruid);
    }
    
    /**
     * 按照ID查找
     * @param id
     * @return
     * @throws SQLException 
     */
    @GetCacheMark("shopOnepage_${0}")
    public ShopOnepage findById(int id) throws SQLException
    {
        String sql=sqlheader+" WHERE tid=?";
        return dataFactory.one(ShopOnepage.class,sql, id);
    }
    
    /**
     * 按店铺查询基本数据 id(int)，title(String)
     * @param shopid
     * @return List<Map>
     * @throws SQLException 
     */
    @GetCacheMark("shopfindSimpleByShop_${0}")
    public List findSimpleByShop(int shopid) throws SQLException
    {
        String sql="SELECT id,title FROM "+table+" WHERE writeruid=?";
        return dataFactory.rowsWithOutObject(sql, shopid);
    }
    
    /**
     * 插入数据
     * @param arg
     * @return
     * @throws SQLException 
     */
    public int insert(ShopOnepage arg)throws SQLException{
        return dataFactory.insert(arg, table);
    }
    
}
